#ifndef RP2OPENGLFRAMEBUFFER_H
#define RP2OPENGLFRAMEBUFFER_H

#include "Rp2OpenGLRenderer.h"
#include "Rp2Main.h"
#include "Rp2FrameBuffer.h"

namespace Rp2
{

class OpenGLFrameBuffer : public FrameBuffer
{
	RP2_DECLARE_INITIALIZE;

public:
    OpenGLFrameBuffer (FormatType eFormat, DepthType eDepth,
        StencilType eStencil, BufferingType eBuffering,
        MultisamplingType eMultisampling, Renderer* pkRenderer,
        Texture* pkTarget);

    virtual ~OpenGLFrameBuffer ();

    bool InitializeBuffer ();
    void TerminateBuffer ();

    virtual void Enable ();
    virtual void Disable ();
    virtual void CopyToTexture (bool bFillImage);
    virtual void CopyTo (VertexBuffer* pkVBuffer, bool bCopyToSystemMemory);

protected:
    GLuint m_uiFrameBufferID;
    GLuint m_uiDepthBufferID;
    GLuint m_uiStencilBufferID;
    GLuint m_uiTargetID;
    bool m_bEnabled;

    // TO DO.  What about buffering and multisampling?

    // factory functions
    static FrameBuffer* Create (FormatType eFormat, DepthType eDepth,
        StencilType eStencil, BufferingType eBuffering,
        MultisamplingType eMultisampling, Renderer* pkRenderer,
        Texture* pkTarget);

    static void Destroy (FrameBuffer* pkBuffer);

};

RP2_REGISTER_INITIALIZE(OpenGLFrameBuffer);

}

#endif